package com.hp.attendance.serlvet.history.StaffFile;

import com.hp.attendance.entity.History;
import com.hp.attendance.entity.HistoryBys;
import com.hp.attendance.entity.PageInfo;
import com.hp.attendance.service.HistoryBysService;
import com.hp.attendance.service.HistoryService;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.sql.SQLException;
import java.util.List;

@WebServlet("/historyList")
public class FileListServlet extends HttpServlet {
    private HistoryBysService historyBysService = new HistoryBysService();

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
//        try {
//            List<History> list = historyService.getList();
//            req.setAttribute("lists",list);
//            req.getRequestDispatcher("/pages/history_list_4.jsp").forward(req,resp);
//        } catch (SQLException throwables) {
//            throwables.printStackTrace();
//        } catch (ClassNotFoundException e) {
//            e.printStackTrace();
//        } catch (InstantiationException e) {
//            e.printStackTrace();
//        } catch (IllegalAccessException e) {
//            e.printStackTrace();
//        }

        try {
            String pageNo = req.getParameter("pageNo");
            if(pageNo==null ||"".equals(pageNo.trim())){
                pageNo="1";
            }
            PageInfo<HistoryBys> page = historyBysService.getPage(Integer.parseInt(pageNo), 10);
            req.setAttribute("page",page);
            req.getRequestDispatcher("/pages/history_list_4.jsp").forward(req,resp);
        }

        catch (SQLException throwables) {
            throwables.printStackTrace();
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        } catch (InstantiationException e) {
            e.printStackTrace();
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        }

    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doGet(req,resp);
    }
}
